import React, {Component} from 'react';
import {Animated, Easing} from 'react-native';
import {createStackNavigator} from 'react-navigation';

import HomeScreen from './screens/HomeScreen';
import SearchScreen from './screens/SearchScreen';
import BookScreen from './screens/BookScreen';
import ReaderScreen from './screens/ReaderScreen';
import OptionsScreen from './screens/OptionsScreen';

const AppNavigator = createStackNavigator({
    Home: {screen: HomeScreen,},
    Search: {screen: SearchScreen,},
    Book: {screen: BookScreen,},
    Reader: {screen: ReaderScreen,},
    Options: {screen: OptionsScreen,},
}, {
    initialRouteName: 'Home',
    // 2.x使用navigationOptions
    // 3.x使用defaultNavigationOptions
    navigationOptions: {
        header: null,//取消标题栏
        gesturesEnabled: true,
        headerStyle: {
            backgroundColor: '#f4511e',
        },
        headerTintColor: '#fff',
        headerTitleStyle: {
            fontWeight: 'bold',
            flex: 1,
            textAlign: 'center',
        },
        headerBackTitle: null,
    },
    transitionConfig: () => ({
        transitionSpec: {
            duration: 300,
            easing: Easing.out(Easing.poly(4)),
            timing: Animated.timing,
        },
        screenInterpolator: sceneProps => {
            const {layout, position, scene} = sceneProps;
            const {index} = scene;
            const Width = layout.initWidth;
            //沿X轴平移
            const translateX = position.interpolate({
                inputRange: [index - 1, index, index + 1],
                outputRange: [Width, 0, -(Width - 10)],
            });
            //透明度
            const opacity = position.interpolate({
                inputRange: [index - 1, index - 0.99, index],
                outputRange: [0, 1, 1],
            });
            return {opacity, transform: [{translateX}]};
        }
    }),
});

// 2.x
// export default AppNavigator;

// 2.x
class App extends Component {
    render() {
        return (
            <AppNavigator/>
        );
    }
}

export default App;


// 3.x
// export default createAppContainer(AppNavigator);
